ccR.Add_Rotation(
	4,
 	"CC_Druid_Restoration", 
 	"CrazyCactuaR's crap botch of\n cdmicheal's restoration druid.",
	"Druid_Restoration_Talents",
	"Druid_Restoration_Abilities",
	"Druid_Restoration_Features",
	"Druid_Restoration_Setup"
 )

ccR.GUI.Create.Frame("Druid_Restoration_Talents")
ccR.GUI.Create.Checkbox("chkPraise_Jesus", "Praise Jesus", 0, 0, nil, nil, "Druid_Restoration_Talents", "Praise_Jesus")
ccR.GUI.Create.Checkbox("chkPraise_Devil", "Praise Devil", 0, -15, nil, nil, "Druid_Restoration_Talents", "Praise_Devil")
ccR.GUI.Create.Checkbox("chkPraise_Chicken", "Praise Fried Chicken", 0, -30, nil, nil, "Druid_Restoration_Talents", "Praise_Chicken")
ccR.GUI.Create.Frame("Druid_Restoration_Abilities")
ccR.GUI.Create.FontString("fs", "Abilities Frame!", 25, -100, 200, 22, 16, "Druid_Restoration_Abilities")
ccR.GUI.Create.Frame("Druid_Restoration_Features")
ccR.GUI.Create.FontString("fs", "Features Frame!", 25, -100, 200, 22, 16, "Druid_Restoration_Features")
ccR.GUI.Create.Frame("Druid_Restoration_Setup")
	ccR.Default("UseCure", true)
	ccR.Default("Cure_MP", 10)
		ccR.Default("CureMagic", true)
		ccR.Default("CureCurse", true)
		ccR.Default("CurePoison", true)
	ccR.Default("UseSooth", true)
	ccR.Default("Sooth_MP", 25)
	ccR.GUI.Create.CheckEditSave("chkUseCure", "Cure (minimum mp)", 0, 0, nil, nil, "Druid_Restoration_Setup", "UseCure", "Cure_MP")	
		ccR.GUI.Create.Checkbox("chkCure_Magic", "Magic", 10, -15, nil, nil, "Druid_Restoration_Setup", "CureMagic")
		ccR.GUI.Create.Checkbox("chkCure_Curse", "Curse", 10, -30, nil, nil, "Druid_Restoration_Setup", "CureCurse")
		ccR.GUI.Create.Checkbox("chkCure_Poisont", "Poison", 10, -45, nil, nil, "Druid_Restoration_Setup", "CurePoison")
	ccR.GUI.Create.CheckEditSave("chkUseSooth", "Sooth (minimum mp)", 0, -60, nil, nil, "Druid_Restoration_Setup", "UseSooth", "Sooth_MP")	

WildCount = {}
ClusterCount = {}
ClusterPreCount = {}
GenesisCount = {}
onlyPlayers = false
-- Cure
UseCure = ccR.Var("UseCure")
minimumManaToUseCure = ccR.Var("Cure_MP")
local tbl_Cure_Blacklist = {
	"Unstable Affliction",
	"Expel Magic: Fire",
}
cureMagic = ccR.Var("CureMagic")
cureCurse = ccR.Var("CureCurse")
curePoison = ccR.Var("CursePoison")
-- Sooth
useSooth = ccR.Var("UseSooth")
minimumManaToUseSooth = ccR.Var("Sooth_MP")
local tbl_Sooth_Blacklist = {
	"Flip Out",	-- Shado-Pan Ambusher
}
function CC_Druid_Restoration()
	table.wipe(WildCount)
	table.wipe(ClusterCount)
	table.wipe(ClusterPreCount)
	table.wipe(GenesisCount)
	LowestHP = "player"
	SecondLowestHP = "player"
	Tank1 = nil
	Tank2 = nil
	vUnit = nil
--End declarations
	--Tank1 = ""  --overide
	--Tank2 = ""  --overide2

	if ccR.Player.Is.InScenario() then onlyPlayers = false else onlyPlayers = true end

	if ccR.Player.Is.CastingSpell(WRATH) and ClearCast() and ccR.Unit.Health(LowestHP) < 96 then SpellStopCasting() end
	if (GetNumGroupMembers() > 0 and GetNumGroupMembers() <= 5) then WildGrowthCount = 2 else WildGrowthCount = 5 end

	for i = 1, # ccR_Friendly do 
		local vUnit = ccR_Friendly[i]
		table.wipe(ClusterPreCount)
		if ccR.Unit.Exists(vUnit) 
		and ccR.Unit.Is.Alive(vUnit) 
		and (ccR.Unit.Is.APlayer(vUnit) or onlyPlayers == false) 
		and ccR.Unit.Is.InLineOfSight(vUnit) 
		and ccR.Unit.Distance(vUnit, "player") <= 60
		then
			--Tanks
			if ccR.Unit.Is.APlayer(vUnit) and (Tank1 == nil or Tank2 == nil) then
				if ccR.Unit.Is.Tank(vUnit) and Tank1 == nil then
					Tank1 = vUnit
				elseif ccR.Unit.Is.Tank(vUnit) and Tank2 == nil then
					Tank2 = vUnit
				end
			end
			if ccR.Unit.Distance(vUnit, "player") < 40 
			and ValidToHeal(vUnit) 
			and not ccR.Unit.Has.Debuff(vUnit, 159220) 
			and not (ClearCast() and ccR.Unit.Name(vUnit) == "Living Mushroom") 
			then
				--Lowest HP
				if ccR.Unit.Health(vUnit) < ccR.Unit.Health(LowestHP) then
					SecondLowestHP = LowestHP
					LowestHP = vUnit
				elseif ccR.Unit.Health(vUnit) == ccR.Unit.Health(LowestHP) then
					if UnitHealthMax(vUnit) < UnitHealthMax(LowestHP) then
						SecondLowestHP = LowestHP
						LowestHP = vUnit
					else
						SecondLowestHP = vUnit
					end
				end
				--Counts
--				if ccR.Unit.Health(vUnit) < 83 then	table.insert(WildCount, vUnit) end
				if ccR.Unit.Health(vUnit) < 83 then	WildCount[#WildCount+1]= vUnit end
				if Tank1 == nil and ccR.Unit.Exists("Oto The Protector") then
					Tank1 = "Oto The Protector"
				elseif Tank1 == nil and ccR.Unit.Exists("Sikari the Mistweaver") then
					Tank1 = "Sikari the Mistweaver"
				elseif Tank1 == nil and ccR.Unit.Exists("Resilient Arcane Elemental") then
					Tank1 = "Resilient Arcane Elemental"
				--elseif ccR.Unit.Exists("Aeda Brightdawn") then
					--Tank1 = "Aeda Brightdawn"
				--elseif Tank1 == nil and Tank2 == nil then
					--Tank1 = "player"
				end
				--if ccR.Unit.Name(vUnit) == "Aeda Brightdawn" then
				--	Tank1 = vUnit
				--end
				for f = 1, # ccR_Friendly do
					local vvvUnit = ccR_Friendly[f]
					if ccR.Unit.Distance(vvvUnit, vUnit) <= 10 and (ccR.Unit.Is.APlayer(vvvUnit)) and ValidToHeal(vvvUnit) then
--						table.insert(ClusterPreCount, vvvUnit)
						ClusterPreCount[#ClusterPreCount+1]= vvvUnit
					end 
				end
				if (ClusterPreCount and # ClusterPreCount > # ClusterCount) or ClusterCount == nil then
					table.wipe(ClusterCount)
					for f = 1, # ccR_Friendly do
						local vvvUnit = ccR_Friendly[f]
						if ccR.Unit.Distance(vvvUnit, vUnit) <= 10 and (ccR.Unit.Is.APlayer(vvvUnit)) and ValidToHeal(vvvUnit) then
--							table.insert(ClusterCount, vvvUnit)
							ClusterCount[#ClusterCount+1]= vvvUnit
						end 
					end
				end
				if UseCure 
				and ccR.Player.Mana() >= minimumManaToUseCure
				then
					Cure("player")
					Cure(vUnit)
				end
			end
			if ccR.Unit.Health(vUnit) < 50 and (ccR.Unit.Has.MyBuff(vUnit, REJUVENATION) or ccR.Unit.Has.MyBuff(vUnit, GERMINATION)) then
--				table.insert(GenesisCount, vUnit)
				GenesisCount[#GenesisCount+1]= vUnit
			end
		end
	end
	
	-- Wild Mushroom
	if SpellIsTargeting() then CastAtPosition(GetAveragePositionOfObjects(ClusterCount)); ccR.PrintToChat("Casting Targeted: " .. #ClusterCount) end
	----
	if ccR.Spell.Is.Ready(NATURES_VIGIL) and ccR.Player.Has.Buff(TREE_OF_LIFE) then	ccR.Cast.Spell(NATURES_VIGIL)	end
	if ccR.Spell.Is.Ready(SOOTH) and useSooth and (tLastSoothUsed == nil or (GetTime()-tLastSoothUsed >= 1.0)) then
		for x = 1, # ccR_Enemies_In_Combat do
			local vUnit = ccR_Enemies_In_Combat[x]
			if ccR.Unit.Exists(vUnit) and ccR.Unit.Distance("player", vUnit) <= 40 then
				for i = 1, 40 do 
				 	local name, _, _, _, buffType = UnitAura(vUnit, i) 
				 	if name == nil or tContains(tbl_Sooth_Blacklist, name) then break else if buffType == "" then ccR.Cast.Spell(SOOTH, vUnit) tLastSoothUsed = GetTime() ccR.PrintToChat("Sooth: " .. name .. " from " .. ccR.Unit.Name(vUnit)) return end end
				end
			end
		end
	end
	if ccR.Spell.Is.Ready(IRONBARK) then
		if not ccR.Unit.Has.Buff(Tank1, IRONBARK) and Tank1 and ValidToHeal(Tank1) and (ccR.Unit.Health(Tank1) < 60 or ccR.Unit.Has.Debuff(Tank1, 159220)) then ccR.Cast.Spell(IRONBARK, Tank1)
		elseif not ccR.Unit.Has.Buff(Tank2, IRONBARK) and Tank2 and ValidToHeal(Tank2) and (ccR.Unit.Health(Tank2) < 60 or ccR.Unit.Has.Debuff(Tank2, 159220)) then ccR.Cast.Spell(IRONBARK, Tank2)
		elseif not ccR.Unit.Has.Buff(LowestHP, IRONBARK) and LowestHP and ValidToHeal(LowestHP) and ccR.Unit.Health(LowestHP) < 60 and not Tank1 and not Tank2 then ccR.Cast.Spell(IRONBARK, LowestHP)
		end
	end

	--Rejuve
	if ccR.Spell.Is.Ready(SWIFTMEND, true) and LowestHP and ValidToHeal(LowestHP) and (ccR.Unit.Health(LowestHP) < 30 or not ccR.Player.Has.Buff(HARMONY)) and not ccR.Unit.Has.Debuff(LowestHP, 159220) and (ccR.Unit.Has.MyBuff(LowestHP, REJUVENATION) or ccR.Unit.Has.MyBuff(LowestHP, REGROWTH)) then ccR.Cast.Spell(SWIFTMEND, LowestHP)
	elseif ccR.Spell.Is.Ready(REGROWTH) and LowestHP and ValidToHeal(LowestHP) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS) or ccR.Player.Has.Buff(TREE_OF_LIFE)) and not ccR.Unit.Has.Debuff(LowestHP, 159220) and (ccR.Unit.Health(LowestHP) < 30 or (ccR.Unit.Health(LowestHP) <= 93 and ClearCast())) then UseNaturesSwiftness() ccR.Cast.Spell(REGROWTH, LowestHP)
	elseif ccR.Spell.Is.Ready(SWIFTMEND, true) and SecondLowestHP and ValidToHeal(SecondLowestHP) and (ccR.Unit.Health(SecondLowestHP) < 30 or not ccR.Player.Has.Buff(HARMONY)) and not ccR.Unit.Has.Debuff(SecondLowestHP, 159220) and (ccR.Unit.Has.MyBuff(SecondLowestHP, REJUVENATION) or ccR.Unit.Has.MyBuff(SecondLowestHP, REGROWTH)) then ccR.Cast.Spell(SWIFTMEND, SecondLowestHP)
	elseif ccR.Spell.Is.Ready(REGROWTH) and SecondLowestHP and ValidToHeal(SecondLowestHP) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS) or ccR.Player.Has.Buff(TREE_OF_LIFE)) and not ccR.Unit.Has.Debuff(SecondLowestHP, 159220) and (ccR.Unit.Health(SecondLowestHP) < 30 or (ccR.Unit.Health(SecondLowestHP) <= 93 and ClearCast())) then UseNaturesSwiftness() ccR.Cast.Spell(REGROWTH, SecondLowestHP)
	elseif ccR.Spell.Is.Ready(LIFEBLOOM) and Tank1 and ValidToHeal(Tank1) and (not ccR.Unit.Has.MyBuff(Tank1, LIFEBLOOM) or ccR.Unit.MyBuffDuration(Tank1, LIFEBLOOM, "<=", 4.5)) and not ccR.Unit.Has.MyBuff(Tank2, LIFEBLOOM)  then ccR.Cast.Spell(LIFEBLOOM, Tank1)
	elseif ccR.Spell.Is.Ready(LIFEBLOOM) and Tank2 and ValidToHeal(Tank2) and (not ccR.Unit.Has.MyBuff(Tank2, LIFEBLOOM) or ccR.Unit.MyBuffDuration(Tank2, LIFEBLOOM, "<=", 4.5)) and not ccR.Unit.Has.MyBuff(Tank1, LIFEBLOOM) then	ccR.Cast.Spell(LIFEBLOOM, Tank2)
	elseif ccR.Spell.Is.Ready(LIFEBLOOM) and not Tank1 and not Tank2 and (not ccR.Unit.Has.MyBuff("player", LIFEBLOOM) or ccR.Unit.MyBuffDuration("player", LIFEBLOOM, "<=", 4.5)) and not ccR.Unit.Has.MyBuff("player", LIFEBLOOM) then ccR.Cast.Spell(LIFEBLOOM, "player")
	elseif ccR.Spell.Is.Ready(REGROWTH) and LowestHP and ValidToHeal(LowestHP) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS) or ccR.Player.Has.Buff(TREE_OF_LIFE)) and not ccR.Unit.Has.Debuff(LowestHP, 159220) and (ccR.Unit.Health(LowestHP) < 20 or (ccR.Unit.Health(LowestHP) <= 60 and ccR.Player.Has.Buff(TREE_OF_LIFE)) or ClearCast()) then UseNaturesSwiftness() ccR.Cast.Spell(REGROWTH, LowestHP)
	elseif ccR.Spell.Is.Ready(REGROWTH) and SecondLowestHP and ValidToHeal(SecondLowestHP) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS) or ccR.Player.Has.Buff(TREE_OF_LIFE)) and not ccR.Unit.Has.Debuff(SecondLowestHP, 159220) and (ccR.Unit.Health(SecondLowestHP) < 20 or (ccR.Unit.Health(SecondLowestHP) <= 60 and ccR.Player.Has.Buff(TREE_OF_LIFE)) or ClearCast()) then UseNaturesSwiftness() ccR.Cast.Spell(REGROWTH, SecondLowestHP)
	elseif ccR.Spell.Is.Ready(HEALING_TOUCH) and Tank1 and ValidToHeal(Tank1) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS)) and not ccR.Unit.Has.Debuff(Tank1, 159220) and ccR.Unit.Has.MyBuff(Tank1, LIFEBLOOM) and ccR.Unit.Health(Tank1) < 60 and not ccR.Player.Has.Buff(TREE_OF_LIFE) then ccR.Cast.Spell(HEALING_TOUCH, Tank1)
	elseif ccR.Spell.Is.Ready(HEALING_TOUCH) and Tank2 and ValidToHeal(Tank2) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS)) and not ccR.Unit.Has.Debuff(Tank2, 159220) and ccR.Unit.Has.MyBuff(Tank2, LIFEBLOOM) and ccR.Unit.Health(Tank2) < 60 and not ccR.Player.Has.Buff(TREE_OF_LIFE) then ccR.Cast.Spell(HEALING_TOUCH, Tank2)
	elseif ccR.Spell.Is.Ready(WILD_GROWTH) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS)) and WildCount and # WildCount >= WildGrowthCount then ccR.Cast.Spell(WILD_GROWTH, "player") ccR.PrintToChat("Casting Wild Growth: " .. #WildCount)
	elseif ccR.Spell.Is.Ready(GENESIS) and GenesisCount and # GenesisCount >= 6 then ccR.Cast.Spell(GENESIS) ccR.PrintToChat("Casting Genesis: " .. #GenesisCount)
	elseif ccR.Spell.Is.Ready(REJUVENATION) and LowestHP and ValidToHeal(LowestHP) and ccR.Unit.Health(LowestHP) < 90 and (not ccR.Unit.Has.MyBuff(LowestHP, REJUVENATION) or ccR.Unit.MyBuffDuration(LowestHP, REJUVENATION, "<", 4.5)) then ccR.Cast.Spell(REJUVENATION, LowestHP)
	elseif ccR.Spell.Is.Ready(REJUVENATION) and SecondLowestHP and ValidToHeal(SecondLowestHP) and ccR.Unit.Health(SecondLowestHP) < 85 and (not ccR.Unit.Has.MyBuff(SecondLowestHP, REJUVENATION) or ccR.Unit.MyBuffDuration(SecondLowestHP, REJUVENATION, "<", 4.5)) then ccR.Cast.Spell(REJUVENATION, SecondLowestHP)
	elseif ccR.Spell.Is.Ready(REJUVENATION) and LowestHP and ValidToHeal(LowestHP) and ccR.Player.Has.Talent(GERMINATION_TALENT) and ccR.Unit.Health(LowestHP) < 90 and ccR.Unit.Has.MyBuff(LowestHP, REJUVENATION) and (not ccR.Unit.Has.MyBuff(LowestHP, GERMINATION) or ccR.Unit.MyBuffDuration(LowestHP, GERMINATION, "<=", 4.5)) then ccR.Cast.Spell(REJUVENATION, LowestHP)
	elseif ccR.Spell.Is.Ready(REJUVENATION) and SecondLowestHP and ValidToHeal(SecondLowestHP) and ccR.Player.Has.Talent(GERMINATION_TALENT) and ccR.Unit.Health(SecondLowestHP) < 85 and ccR.Unit.Has.MyBuff(SecondLowestHP, REJUVENATION) and (not ccR.Unit.Has.MyBuff(SecondLowestHP, GERMINATION) or ccR.Unit.MyBuffDuration(SecondLowestHP, GERMINATION, "<", 4.5)) then ccR.Cast.Spell(REJUVENATION, SecondLowestHP)
	elseif ccR.Spell.Is.Ready(REJUVENATION) and Tank1 and ValidToHeal(Tank1) and (not ccR.Unit.Has.MyBuff(Tank1, REJUVENATION) or ccR.Unit.MyBuffDuration(Tank1, REJUVENATION, "<=", 4.5)) then ccR.Cast.Spell(REJUVENATION, Tank1)
	elseif ccR.Spell.Is.Ready(REJUVENATION) and Tank2 and ValidToHeal(Tank2) and (not ccR.Unit.Has.MyBuff(Tank2, REJUVENATION) or ccR.Unit.MyBuffDuration(Tank2, REJUVENATION, "<=", 4.5)) then ccR.Cast.Spell(REJUVENATION, Tank2)
	elseif ccR.Spell.Is.Ready(REJUVENATION) and Tank1 and ValidToHeal(Tank1) and ccR.Player.Has.Talent(GERMINATION_TALENT) and ccR.Unit.Has.MyBuff(Tank1, REJUVENATION) and (not ccR.Unit.Has.MyBuff(Tank1, GERMINATION) or ccR.Unit.MyBuffDuration(Tank1, GERMINATION, "<=", 4.5)) and ccR.Unit.Health(Tank1) < 90 then ccR.Cast.Spell(REJUVENATION, Tank1)
	elseif ccR.Spell.Is.Ready(REJUVENATION) and Tank2 and ValidToHeal(Tank2) and ccR.Player.Has.Talent(GERMINATION_TALENT) and ccR.Unit.Has.MyBuff(Tank2, REJUVENATION) and (not ccR.Unit.Has.MyBuff(Tank2, GERMINATION) or ccR.Unit.MyBuffDuration(Tank2, GERMINATION, "<=", 4.5)) and ccR.Unit.Health(Tank2) < 90 then ccR.Cast.Spell(REJUVENATION, Tank2)
	elseif ccR.Spell.Is.Ready(HEALING_TOUCH) and Tank1 and ValidToHeal(Tank1) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS)) and not ccR.Unit.Has.Debuff(Tank1, 159220) and ccR.Unit.Has.MyBuff(Tank1, LIFEBLOOM) and ccR.Unit.Health(Tank1) < 80 and not ccR.Player.Has.Buff(TREE_OF_LIFE) then ccR.Cast.Spell(HEALING_TOUCH, Tank1)
	elseif ccR.Spell.Is.Ready(HEALING_TOUCH) and Tank2 and ValidToHeal(Tank2) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS)) and not ccR.Unit.Has.Debuff(Tank2, 159220) and ccR.Unit.Has.MyBuff(Tank2, LIFEBLOOM) and ccR.Unit.Health(Tank2) < 80 and not ccR.Player.Has.Buff(TREE_OF_LIFE) then ccR.Cast.Spell(HEALING_TOUCH, Tank2)
	elseif ccR.Spell.Is.Ready(HEALING_TOUCH) and LowestHP and ValidToHeal(LowestHP) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS)) and ccR.Unit.Health(LowestHP) < 60 and not ccR.Unit.Has.Debuff(LowestHP, 159220) and ccR.Unit.Has.MyBuff(LowestHP, LIFEBLOOM) and not ccR.Player.Has.Buff(TREE_OF_LIFE) then ccR.Cast.Spell(HEALING_TOUCH, LowestHP)
	elseif ccR.Spell.Is.Ready(SWIFTMEND, true) and LowestHP and ValidToHeal(LowestHP) and (ccR.Unit.Health(LowestHP) < 50 or not ccR.Player.Has.Buff(HARMONY)) and not ccR.Unit.Has.Debuff(LowestHP, 159220) and (ccR.Unit.Has.MyBuff(LowestHP, REJUVENATION) or ccR.Unit.Has.MyBuff(LowestHP, REGROWTH)) then ccR.Cast.Spell(SWIFTMEND, LowestHP)
	elseif ccR.Spell.Is.Ready(REGROWTH) and LowestHP and ValidToHeal(LowestHP) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS) or ccR.Player.Has.Buff(TREE_OF_LIFE)) and not ccR.Unit.Has.Debuff(LowestHP, 159220) and (ccR.Unit.Health(LowestHP) < 50 or (ccR.Unit.Health(LowestHP) <= 93 and ClearCast())) then UseNaturesSwiftness() ccR.Cast.Spell(REGROWTH, LowestHP)
	elseif ccR.Spell.Is.Ready(SWIFTMEND, true) and SecondLowestHP and ValidToHeal(SecondLowestHP) and (ccR.Unit.Health(SecondLowestHP) < 50 or not ccR.Player.Has.Buff(HARMONY)) and not ccR.Unit.Has.Debuff(SecondLowestHP, 159220) and (ccR.Unit.Has.MyBuff(SecondLowestHP, REJUVENATION) or ccR.Unit.Has.MyBuff(SecondLowestHP, REGROWTH)) then ccR.Cast.Spell(SWIFTMEND, SecondLowestHP)
	elseif ccR.Spell.Is.Ready(REGROWTH) and SecondLowestHP and ValidToHeal(SecondLowestHP) and (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS) or ccR.Player.Has.Buff(TREE_OF_LIFE)) and not ccR.Unit.Has.Debuff(SecondLowestHP, 159220) and (ccR.Unit.Health(SecondLowestHP) < 50 or (ccR.Unit.Health(SecondLowestHP) <= 93 and ClearCast())) then UseNaturesSwiftness() ccR.Cast.Spell(REGROWTH, SecondLowestHP)
	end
	--Blanket Rejuve
	if ccR.Spell.Is.Ready(REJUVENATION) then
		for i = 1, # ccR_Friendly do 
			local vUnit = ccR_Friendly[i]
			if ccR.Unit.Exists(vUnit) 
			and ccR.Unit.Is.Alive(vUnit) 
			and (ccR.Unit.Is.APlayer(vUnit) or onlyPlayers == false) 
			and ccR.Unit.Is.InLineOfSight(vUnit) 
			and ccR.Unit.Distance(vUnit, "player") <= 40 then
				if ccR.Unit.Distance(vUnit, "player") <= 40 
				and (not ccR.Unit.Has.MyBuff(vUnit, REJUVENATION)) 
				and (ccR.Unit.Health(vUnit) < 95 or (ccR.Player.Has.Buff(TREE_OF_LIFE) and ccR.Unit.Health(vUnit) < 94 ))
				then
					ccR.Cast.Spell(REJUVENATION, vUnit)
				end
			end
		end
	end
	if ccR.Player.Has.Talent(GERMINATION_TALENT) and ccR.Spell.Is.Ready(REJUVENATION) then
		for i = 1, # ccR_Friendly do 
			local vUnit = ccR_Friendly[i]
			if ccR.Unit.Exists(vUnit) 
			and ccR.Unit.Is.Alive(vUnit) 
			and (ccR.Unit.Is.APlayer(vUnit) or onlyPlayers == false) 
			and ccR.Unit.Is.InLineOfSight(vUnit) 
			and ccR.Unit.Distance(vUnit, "player") <= 40 
			then
				if ccR.Unit.Distance(vUnit, "player") <= 40
				and ccR.Unit.Has.MyBuff(vUnit, REJUVENATION) 
				and (not ccR.Unit.Has.MyBuff(vUnit, GERMINATION)) 
				and (ccR.Unit.Health(vUnit) < 85 or (ccR.Player.Has.Buff(TREE_OF_LIFE) and ccR.Unit.Health(vUnit) < 90 ))
				then
					ccR.Cast.Spell(REJUVENATION, vUnit)
				end
			end
		end
	end

	if ccR.Spell.Is.Ready(WRATH) and not ccR.Player.Is.Moving() and ccR.Player.Has.Talent(DREAM_OF_CENARIUS) and ccR.Unit.Exists("target") and ccR.Target.Is.Attackable() and ccR.Player.Is.Facing("target") and ccR.Spell.CanAttack(WRATH, "target") then ccR.Cast.Attack(WRATH, "target")	else PVE_Solo_AutoWrath() end

end

function PVE_Solo_AutoWrath()
	for x = 1, # ccR_Enemies_In_Combat do
		local vUnit = ccR_Enemies_In_Combat[x]
		if ccR.Unit.Is.Alive(vUnit)
		and ccR.Player.Is.Facing(vUnit)
		and ccR.Spell.CanAttack(WRATH, vUnit)
		and ccR.Player.Has.Talent(DREAM_OF_CENARIUS)
		and not ccR.Player.Is.Moving()
		and ccR.Unit.Is.InCombat(vUnit)
		then
			ccR.Cast.Attack(WRATH, vUnit)
		end
	end
end

function UseNaturesSwiftness()
	if ccR.Spell.Is.Ready(NATURES_SWIFTNESS) and not ClearCast() then ccR.Cast.Spell(NATURES_SWIFTNESS) return else return end
end

function Cure(unit)  
	if ccR.Spell.Is.Ready(NATURESCURE) and HasFullControl() and ccR.Player.Mana() >= minimumManaToUseCure then
		-- Blacklist check
		for i = 1, 40 do
		 	local DebuffName, _, _, _, debuffType = UnitDebuff(unit, i) 
		 	if DebuffName == nil
		 	or tContains(tbl_Cure_Blacklist, DebuffName)
		 	then	
		 		break 
		 	else 
		 		if (cureMagic and debuffType == "Magic") 
		 		or (cureCurse and debuffType == "Curse") 
		 		or (curePoison and debuffType == "Poison") 
		 		then
		 			if ccR.Player.Is.CastingSpell(WRATH) then SpellStopCasting() end
		 			ccR.Cast.Spell(NATURESCURE, unit)	
		 			ccR.PrintToChat("Cure: " .. debuffType .. " on " .. ccR.Unit.Name(unit) .. ".")
		 			return
		 		end
		 	end
		end
	end
end

function ValidToHeal(tunit)
	if ccR.Unit.Distance(tunit, "player") <= 40 and ccR.Unit.Exists(tunit) and ccR.Unit.Is.Alive(tunit) and ccR.Unit.Is.InLineOfSight(tunit) then
		return true
	else
		return false
	end
end

function ClearCast()
	if ccR.Player.Has.Buff(CLEARCASTING) or ccR.Player.Has.Buff(CLEARCASTING_CLARITY) or ccR.Player.Has.Buff(NATURES_SWIFTNESS) then
		return true
	else
		return false
	end
end

